<?php
declare (strict_types = 1);

namespace app\api\controller;
use app\model\BooksModel;
use app\model\RedisModel;
use app\model\UserFbLogModel;
use app\model\UserModel;
use app\model\UserReadingRecordsModel;
use think\App;
use think\facade\Db;

class UserFbLog extends Base {

    private $userFbLogModel;

    private $req;

    private $uid;

    private $page;

    private $limit = 5;

    private $cacheKey="user:";

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->req = request()->param();

        $this->uid = $this->isLogin();

        $this->page = isset($this->req['page']) ? $this->req['page'] : 1;

        $this->limit = isset($this->req['limit']) ? $this->req['limit'] : 1;

        $this->userFbLogModel = new UserFbLogModel();
    }



    public function getUserFbAmount(){

        if(!$this->uid){
            return $this->succ(0);
        }

        $fb = $this->userFbLogModel->getUserTotalFb($this->uid);

        return $this->succ($fb);
    }



    //type = inc  | dec
    public function getUserFbLogList(){

        if(!$this->uid){
            return $this->succ();
        }

        $where=[];
        $where[] = ["uid","=",$this->uid];
        $where[] = ["fb_status","=",1];
        if($this->req["type"] == "inc"){
            $where[] = ["fb",">",0];
        }elseif ($this->req["type"] == "dec"){
            $where[] = ["fb","<",0];
        }

        $total = $this->userFbLogModel->getTotal($where);
        $list = $this->userFbLogModel->getList($where,$this->page,$this->limit,"created_at","DESC");
        if(empty($list)){
            return $this->succ();
        }

        return $this->succData($total,$list);

    }







}
